<template>
  <div class="course_news">
    <div class="course_nav">
      <div
        class="course_list"
        v-for="(item, index2) in topicList"
        :key="index2"
        @click="handelChange(item)"
      >
        {{ item.label }}
      </div>
    </div>
    <div class="course_news_title">
      <p style="margin-right: 20px">{{ routerName }}</p>
    </div>
    <div class="course_news_table">
      <el-table :data="lessonIntroductionList" style="width: 100%">
        <el-table-column fixed prop="label" label="名称"> </el-table-column>
        <el-table-column prop="type" label="类型" width="200">
        </el-table-column>
        <el-table-column prop="createdAt" label="创建时间" width="200">
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="course_news_pagination">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="lessonIntroductionData.page"
        :page-size="lessonIntroductionData.size"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { getLessonIntroductionList } from "@/api/resource";
import topicList from "@/utils/topicList.js";
export default {
  name: "index",
  data() {
    return {
      routerName: "",
      topicList,
      lessonIntroductionData: {
        page: 1,
        size: 10,
        data: {
          keyword: "",
          type: "",
        },
      },
      lessonIntroductionList: [],
      total: 0,
    };
  },
  created() {
    this.routerName = this.$route.query.routerName;
  },
  mounted() {
    this.getLessonIntroductionList(this.lessonIntroductionData);
  },
  computed: {},
  methods: {
    // 获取列表
    getLessonIntroductionList(data) {
      getLessonIntroductionList(data).then((response) => {
        if (response.data.code === 20000) {
          const { list, totalRecords } = response.data.results;
          this.total = totalRecords;
          this.lessonIntroductionList = list.map((item) => {
            return {
              id: item.id,
              label: item.title,
              createdAt: item.createdAt,
              type: item.type,
            };
          });
        }
      });
    },
    // 详情
    handleClick(row) {
      this.$router.push({
        path: "/generalSituation/introduction",
        query: {
          routerName: this.routerName,
          lessonIntroductionId: row.id,
        },
      });
    },
    handleCurrentChange(val) {
      this.lessonIntroductionData.page = val;
      this.getlessonIntroductionList(this.lessonIntroductionData);
    },
    handelChange(val) {
      if (val.label === "全部") {
        this.lessonIntroductionData.data.type = "";
      } else {
        this.lessonIntroductionData.data.type = val.label;
      }

      this.getLessonIntroductionList(this.lessonIntroductionData);
    },
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.course_news {
  .course_nav {
    display: flex;
    margin-bottom: 20px;
  }
  .is_course_list {
    color: #0a7b19;
    background: #f4fff6;
    padding: 0 40px;
    font-weight: bold;
    height: 40px;
    line-height: 40px;
    border: 1px solid #f1f1f1;
    cursor: pointer;
  }

  .course_list {
    padding: 0 30px;
    font-weight: bold;
    color: #333;
    background: white;
    height: 40px;
    line-height: 40px;
    border: 1px solid #f1f1f1;
    cursor: pointer;
    &:hover {
      color: #0a7b19;
      background: #f4fff6;
    }
  }
  .course_news_title {
    height: 40px;
    background: #f1f1f1;
    text-align: right;
    line-height: 40px;
    font-weight: bold;
    font-size: 21px;
    color: #0a7b19;
  }
  .course_news_table {
    margin-top: 20px;
    margin-bottom: 50px;
    .el-button--text {
      color: #0a7b19;
    }
  }
  .course_news_pagination {
    width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    margin-bottom: 50px;
  }
}
</style>
